//
//  HeadButtonView.m
//  RedManStock
//
//  Created by lanou3g on 15/7/21.
//  Copyright (c) 2015年 lanou3g. All rights reserved.
//

#import "HeadButtonView.h"
#import "UIDefine.h"
#import "ThreeListViewController.h"
@implementation HeadButtonView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
//- (void)initWithTitleArray:(NSArray *)TitleArray
//                imageArray:(NSArray *)imageArray;

- (instancetype)initWithFrame:(CGRect)frame{
    if (self=[super initWithFrame:frame]) {
        
        self.buttonArray=[NSMutableArray array];
        self.backgroundColor=[UIColor whiteColor];
        
        CGFloat width=frame.size.width/3;
        CGFloat height=frame.size.height;
        
        for (int i=0; i<3; i++) {
            
            UIButton *button=[[UIButton alloc]initWithFrame:CGRectMake(i*width, 0, width, height)];
            NSString * imageName = [NSString stringWithFormat:@"threeButton_%d@2x",i];
            [button setImage:[[UIImage imageNamed:imageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];

            [button addTarget:self action:@selector(jumptoList:) forControlEvents:UIControlEventTouchUpInside];
            
            button.tag=100+i;
            button.layer.borderWidth=1.0;
            button.layer.borderColor=(__bridge CGColorRef)([UIColor grayColor]);
            
            [self.buttonArray addObject:button];
            [self addSubview:button];
        }
        
    }
    return self;
}

//获得View所在的controller
- (UIViewController *)viewController {
    for (UIView *next = [self superview]; next; next = next.superview) {
        UIResponder *nextResponder = [next nextResponder];
        if ([nextResponder isKindOfClass:[UIViewController class]]) {
            return (UIViewController *)nextResponder;
        }
    }
    return nil;
}

- (void)jumptoList:(UIButton *)button{
    
    ThreeListViewController *threeListVC=[[ThreeListViewController alloc]initWithHeader:YES footer:YES];
    threeListVC.requestId=button.tag-100;
    threeListVC.hidesBottomBarWhenPushed=YES;
    [self.viewController.navigationController pushViewController:threeListVC animated:YES];
}


@end
